import time

from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select


class PageBackendBatchLoading():
    def __init__(self, driver):
        self.driver = driver

 #选择数据格式
    def ele_data_format(self):
        ele = self.driver.find_element(By.ID, 'data_cat')
        select = Select(ele)
        select.select_by_value('ecshop')
        time.sleep(1)

    #选择所属分类
    def ele_choos_classify(self):
        ele = self.driver.find_element(By.ID, 'cat')
        select = Select(ele)
        select.select_by_value('182')
        time.sleep(1)

    #上传CSV文件
    def ele_upload_file(self):
        self.driver.find_element(By.NAME, 'file').send_keys(r'C:\Users\DR\Desktop\goods_list.csv')
        time.sleep(3)

    #点击【确认】按钮
    def ele_accept_submit(self):
        self.driver.find_element(By.ID, 'submit').click()
        time.sleep(2)

    #点击【确认】按钮（二次）
    def ele_accept_submit_two(self):
        self.driver.find_element(By.NAME, 'submit').click()
        # 进入右侧mainframe

    def ele_main_frame(self):
        self.driver.switch_to.frame('main-frame')

        # 退出frame

    def ele_frame_out(self):
        self.driver.switch_to.default_content()

    def upload_list(self):
        self.ele_main_frame()
        self.ele_data_format()
        self.ele_choos_classify()
        self.ele_upload_file()
        self.ele_accept_submit()
        self.ele_accept_submit_two()
        self.ele_frame_out()